package com.personnel.controller;

import com.personnel.pojo.Department;
import com.personnel.service.DepartmentService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 部门表(Department)表控制层
 *
 * @author yuepeng
 * @since 2022-01-19 11:28:39
 * @version 1.0
 */
@RestController
@RequestMapping("/department")
public class DepartmentController {
    /**
     * 服务对象
     */
    @Resource
    private DepartmentService departmentService;

    /**
     * 通过主键查询单条数据
     * @param index  需要查询的页码
     * @param name  模糊查询的内容
     * @return 单条数据
     */
    @RequestMapping(value = "/selectForPage", method = RequestMethod.GET)

    public Map<String, Object> selectForPage(@RequestParam(name = "page") int index, String name) {
        return this.departmentService.selectForPage(index, name);
    }
    
    /**
     * 查询所有数据
     * @return 返回所有数据
     */
    @GetMapping(value = "/selectAll")
    public Map<String, Object> selectAll() {
        return this.departmentService.selectAll();
    }
    
    /**
     * 通过主键删除单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @RequestMapping(value = "/deleteById", method = RequestMethod.POST)
    public Map<String, Object> deleteById(@RequestParam("id") String id) {
        return this.departmentService.deleteById(id);
    }
    
    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @RequestMapping(value = "/selectById", method = RequestMethod.GET)
    public Map<String, Object> selectById(Integer id) {
        return this.departmentService.selectById(id);
    }
    
    /**
     * 通过主键更新单条数据
     *
     * @param department 一个数据库对应的POJO数据对象
     * @return 单条数据
     */
    @RequestMapping(value = "/updateById", method = RequestMethod.POST)
    public Map<String, Object> updateById(@RequestBody  Department department) {
        return this.departmentService.updateById(department);
    }
    
    /**
     * 通过一个pojo对象新增单条数据
     *
     * @param department 一个数据库对应的POJO数据对象
     * @return 返回插入的主键id
     */
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public Map<String, Object> insert(@RequestBody Department department) {
        return this.departmentService.insert(department);
    }

}